<!--
 * @Author: coman
 * @LastEditors: coman
 * @Date: 2020-06-15 17:30:37
 * @motto: No pain,No gain
 * @LastEditTime: 2020-06-15 18:15:40
--> 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!--  封装一个十六进制的随机颜色 函数  #fff111-->
    <input type="button" value="更改颜色" id="btn">
    <script>
       
        btn.onclick= function(){
            var str="";
            for(var i=0;i<6;i++){
             str += parseInt((Math.random()*16)).toString(16);
            }
            console.log(str);
            
            document.body.style.background="#"+str;
        }
    </script>
</body>
</html>